<template>
  <view>
    <custom-navbar title="发布任务" />
    <basic-components />
    <view class="basic-search-box" :data-theme="cueTheme" @tap="addBtn.visible = false">
      <view class="m-t-10 m-b-5 task-date">
        <view class="title">
          <image class="image" src="~@/static/img/task2.png" />
          任务时间
        </view>
        <view class="date" @tap="dataPickerVisible = true">
          <view>{{ addForm.form.taskDate }}</view>
          <image class="image" src="~@/static/img/date.png" />
        </view>
      </view>
      <scroll-view scroll-y="true" :style="setScrollStyle(45)" class="scroll-data">
        <template v-if="dataGrid.data.length">
          <view v-for=" (item) of dataGrid.data " :key="item.id" class="table-box">
            <view class="table-row">
              <view class="left">
                <image class="image" :src="setImgUrl(item)" />
                <view class="left-value">
                  <view>{{ item.taskName }}</view>
                </view>
              </view>
              <view class="right">
                <text>{{ item.planTime }} ( 分钟 )</text>
                <text>预计耗时</text>
              </view>
            </view>

            <view class="baisc-row">
              <text>优先级</text>
              <view>
                <image v-for=" i in item.priority " :key="i" class="image m-l-5" src="~@/static/img/xing.png" />
              </view>
            </view>

            <view class="baisc-row">
              <text>任务类型</text>
              <text> {{ item.taskType }}</text>
            </view>

            <view class="baisc-row">
              <text>开始时间</text>
              <text> {{ item.startTime ? item.startTime : '暂无开始时间' }}</text>
            </view>

            <view class="baisc-row">
              <text>结束时间</text>
              <text> {{ item.endTime ? item.endTime : '暂无结束时间' }}</text>
            </view>

            <view v-if="item.status === 0" class="buttons">
              <view class="edit iconfont icon-bianji"
                @tap="pageSkip('/pages/task/addType/save/index', item, basicFlag.EDIT)" />
              <view class="del iconfont icon-shanchu1" @tap="openDialog(item, basicFlag.REMOVE)" />
            </view>
          </view>
          <view class="row-placeholder" />
        </template>

        <view v-else-if="dataGrid.loading !== 1" class="main-no-data">
          暂未发布任务
        </view>
      </scroll-view>
    </view>

    <uni-fab ref="fab" :pattern="addBtn.pattern" :content="addBtn.content" :horizontal="addBtn.horizontal"
      :vertical="addBtn.vertical" @fabClick="fabClick" />

    <view class="add-type1" :class="[!addBtn.visible ? 'hide-btn1' : '']"
      @tap="pageSkip('/pages/task/addType/save/index', {}, basicFlag.ADD)">
      单条任务新增
    </view>
    <view class="add-type2" :class="[!addBtn.visible ? 'hide-btn2' : '']"
      @tap="pageSkip('/pages/task/addType/saveByChoose/index', {}, basicFlag.ADD)">
      从快速选择中新增
    </view>
    <view class="add-type3" :class="[!addBtn.visible ? 'hide-btn3' : '']"
      @tap="pageSkip('pages/task/addType/saveByHis/index', {}, basicFlag.ADD)">
      从历史数据中新增
    </view>

    <m-modal :visible.sync="dialogParams.visible" :content="dialogParams.content" :apis="dialogParams.apis"
      :use-flag="dialogParams.useFlag" :params="dialogParams.params" :select-row-data="dialogParams.selectRowData"
      @submit="search" />

    <m-data-picker v-model="addForm.form.taskDate" :visible.sync="dataPickerVisible" type="date" @confirm="search" />
  </view>
</template>

<script>
import { getFiles } from "@/utils/getFiles"
const files = require.context("./mixins", false, /\.js$/)
const mixins = getFiles(files)

export default {
  mixins: [...mixins],
  onShow() {
    this.addBtn.visible = false
    this.search()
  },
  data() {
    return {
      addBtn: {
        visible: false,
        title: "uni-fab",
        directionStr: "垂直",
        horizontal: "right",
        vertical: "bottom",
        direction: "horizontal",
        pattern: {
          buttonColor: this.$basicColor.success_color
        }
      }
    }
  },
  methods: {
    fabClick() {
      this.addBtn.visible = !this.addBtn.visible
    }
  }
}
</script>
<style lang="scss" scoped src="./index.scss"></style>
